home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / misc / edu / globe099src.lha / Ami-Globe / EDITEUR.C < prev    next >
C/C++ Source or Header  |  1994-08-27  |  24KB  |  840 lines

  1. /********************************/
  2. /* AmiGlobe                     */
  3. /* T.Landspurg                  */
  4. /* O. Collard                   */
  5. /********************************/
  6.  
  7. /* INCLUDES ********************************************************** */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/io.h>
  11. #include <exec/memory.h>
  12. #include <libraries/dos.h>
  13. #include <intuition/intuition.h>
  14. #include <graphics/gfxmacros.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <fcntl.h>
  20. #include <ctype.h>
  21.  
  22. /* Prototypes */
  23. #include <clib/exec_protos.h>
  24. #include <clib/dos_protos.h>
  25. #include <clib/graphics_protos.h>
  26. #include <clib/intuition_protos.h>
  27.  
  28.  
  29. #include "amiglobe_types.h"
  30. #include "database_types.h"
  31. #include "map_function_protos.h"
  32. #include "read_bin.h"
  33. #include "main_protos.h"
  34.  
  35. struct Window *OpenWindow();
  36.  
  37. #define MOVE_PT 0
  38. #define ADD_SEGMENT 1
  39.  
  40.  
  41. int commande=MOVE_PT;
  42.  
  43. extern  PREFERENCE Pref;        /* Préférences              */
  44. extern  int max_country;        /* Nombre max de pays       */
  45.  
  46. extern  struct Screen *sC;
  47. extern  struct Window *wG;      /* we fetch the RastPort pointer from here */
  48. extern  struct RastPort *rpG;
  49. extern  int signal_wG;
  50.  
  51. int tab_vecteur_temp[100];
  52. int num_vect=0;
  53.  
  54. struct Window *edit_wG;
  55. struct Window *inf_wG;
  56. struct RastPort *edit_rpG,*inf_rpG;
  57.  
  58. extern  BORDER  *tab_vect;
  59. extern  COUNTRY *tab_country;
  60.  
  61. int signal_edit,signal_edit_wG;
  62.  
  63. int start_bord=0;
  64. int flg_quit_inf;
  65.  
  66. void cmd_edit_pays(void);
  67. void cmd_ok(void);
  68. void aff_borders(int,int);
  69. void cmd_add_bord(void);
  70.  
  71. void cmd_move_pt(void)
  72. {
  73.     printf("cmd move pt!\n");
  74.     commande=MOVE_PT;
  75. }
  76.  
  77. void cmd_create_pays(void)
  78. {
  79.     printf("Create pays!\n");
  80.     commande=ADD_SEGMENT;
  81. }
  82.  
  83. void cmd_show_bord(void)
  84. {
  85.     map_show_bords(Pref.country_sel,start_bord,rpG);
  86. }
  87.  
  88. void cmd_show_seg(void)
  89. {
  90.     map_show_borders(rpG);
  91. }
  92.  
  93. void cmd_newname(void)
  94. {
  95.     printf("cmd new name!\n");
  96. }
  97.  
  98. void cmd_del_bord(void)
  99. {
  100.     int i,num_bord;
  101.     int *p_b;
  102.     COUNTRY *p_c;
  103.  
  104.     p_c = &(tab_country[Pref.country_sel]);
  105.     num_bord = (p_c->p_borders)[start_bord];
  106.     printf ("cmd del bord de %d\n",num_bord);
  107.     if (p_c->nb_borders>1)
  108.     {
  109.         p_c->nb_borders--;
  110.         p_b=p_c->p_borders;
  111.         for (i=start_bord;i<p_c->nb_borders;i++)
  112.         {
  113.             p_b[i]=p_b[i+1];
  114.         }
  115.         aff_borders(Pref.country_sel,start_bord);
  116.         redraw_map(-1,rpG);
  117.     }
  118. }
  119.  
  120. void cmd_up(void)
  121. {
  122.     if(start_bord>0)start_bord--;
  123.     aff_borders(Pref.country_sel,start_bord);
  124. }
  125.  
  126. void cmd_down(void)
  127. {
  128.     if(start_bord<(tab_country[Pref.country_sel].nb_borders-1)){
  129.         start_bord++;
  130.         aff_borders(Pref.country_sel,start_bord);
  131.     }
  132. }
  133.  
  134. void cmd_show_pt(void)
  135. {
  136.     printf("cmd show pt !\n");
  137.     map_show_pt(rpG);
  138. }
  139. /*************************************************************************/
  140.  
  141. /*************************************************************************/
  142.  
  143.  
  144. UBYTE infpinfpnaSIBuff[20];
  145. struct StringInfo infpinfpnaSInfo = {
  146.     infpinfpnaSIBuff,   /* buffer where text will be edited */
  147.     NULL,   /* optional undo buffer */
  148.     0,  /* character position in buffer */
  149.     20, /* maximum number of characters to allow */
  150.     0,  /* first displayed character buffer position */
  151.     0,0,0,0,0,  /* Intuition initialized and maintained variables */
  152.     0,  /* Rastport of gadget */
  153.     0,  /* initial value for integer gadgets */
  154.     NULL    /* alternate keymap (fill in if you set the flag) */
  155. };
  156.  
  157. SHORT infpBorderVectors1[] = {
  158.     0,0,
  159.     132,0,
  160.     132,9,
  161.     0,9,
  162.     0,0
  163. };
  164. struct Border infpBorder1 = {
  165.     -1,-1,  /* XY origin relative to container TopLeft */
  166.     3,0,JAM1,   /* front pen, back pen and drawmode */
  167.     5,  /* number of XY vectors */
  168.     infpBorderVectors1, /* pointer to XY vectors */
  169.     NULL    /* next border in list */
  170. };
  171.  
  172. struct IntuiText infpIText1 = {
  173.     1,0,JAM2,   /* front and back text pens, drawmode and fill byte */
  174.     -44,0,  /* XY origin relative to container TopLeft */
  175.     NULL,   /* font pointer or NULL for default */
  176.     "Name:",    /* pointer to text */
  177.     NULL    /* next IntuiText structure */
  178. };
  179.  
  180. struct Gadget infpna = {
  181.     NULL,   /* next gadget */
  182.     81,18,  /* origin XY of hit box relative to window TopLeft */
  183.     131,8,  /* hit box width and height */
  184.     NULL,   /* gadget flags */
  185.     RELVERIFY,  /* activation flags */
  186.     STRGADGET,  /* gadget type flags */
  187.     (APTR)&infpBorder1, /* gadget border or image to be rendered */
  188.     NULL,   /* alternate imagery for selection */
  189.     &infpIText1,    /* first IntuiText structure */
  190.     NULL,   /* gadget mutual-exclude long word */
  191.     (APTR)&infpinfpnaSInfo, /* SpecialInfo structure */
  192.     NULL,   /* user-definable data */
  193.     NULL    /* pointer to user-definable data */
  194. };
  195.  
  196. SHORT infpBorderVectors2[] = {
  197.     0,0,
  198.     55,0,
  199.     55,16,
  200.     0,16,
  201.     0,0
  202. };
  203. struct Border infpBorder2 = {
  204.     -1,-1,  /* XY origin relative to container TopLeft */
  205.     3,0,JAM1,   /* front pen, back pen and drawmode */
  206.     5,  /* number of XY vectors */
  207.     infpBorderVectors2, /* pointer to XY vectors */
  208.     NULL    /* next border in list */
  209. };
  210.  
  211. struct IntuiText infpIText2 = {
  212.     3,0,JAM2,   /* front and back text pens, drawmode and fill byte */
  213.     10,3,   /* XY origin relative to container TopLeft */
  214.     NULL,   /* font pointer or NULL for default */
  215.     "Add",  /* pointer to text */
  216.     NULL    /* next IntuiText structure */
  217. };
  218.  
  219. struct Gadget infps3 = {
  220.     &infpna,    /* next gadget */
  221.     167,84, /* origin XY of hit box relative to window TopLeft */
  222.     54,15,  /* hit box width and height */
  223.     NULL,   /* gadget flags */
  224.     RELVERIFY,  /* activation flags */
  225.     BOOLGADGET, /* gadget type flags */
  226.     (APTR)&infpBorder2, /* gadget border or image to be rendered */
  227.     NULL,   /* alternate imagery for selection */
  228.     &infpIText2,    /* first IntuiText structure */
  229.     NULL,   /* gadget mutual-exclude long word */
  230.     NULL,   /* SpecialInfo structure */
  231.     NULL,   /* user-definable data */
  232.     NULL    /* pointer to user-definable data */
  233. };
  234.  
  235. SHORT infpBorderVectors3[] = {
  236.     0,0,
  237.     55,0,
  238.     55,16,
  239.     0,16,
  240.     0,0
  241. };
  242. struct Border infpBorder3 = {
  243.     -1,-1,  /* XY origin relative to container TopLeft */
  244.     3,0,JAM1,   /* front pen, back pen and drawmode */
  245.     5,  /* number of XY vectors */
  246.     infpBorderVectors3, /* pointer to XY vectors */
  247.     NULL    /* next border in list */
  248. };
  249.  
  250. struct IntuiText infpIText3 = {
  251.     3,0,JAM2,   /* front and back text pens, drawmode and fill byte */
  252.     11,3,   /* XY origin relative to container TopLeft */
  253.     NULL,   /* font pointer or NULL for default */
  254.     "Del",  /* pointer to text */
  255.     NULL    /* next IntuiText structure */
  256. };
  257.  
  258. struct Gadget infps2 = {
  259.     &infps3,    /* next gadget */
  260.     167,66, /* origin XY of hit box relative to window TopLeft */
  261.     54,15,  /* hit box width and height */
  262.     NULL,   /* gadget flags */
  263.     RELVERIFY,  /* activation flags */
  264.     BOOLGADGET, /* gadget type flags */
  265.     (APTR)&infpBorder3, /* gadget border or image to be rendered */
  266.     NULL,   /* alternate imagery for selection */
  267.     &infpIText3,    /* first IntuiText structure */
  268.     NULL,   /* gadget mutual-exclude long word */
  269.     NULL,   /* SpecialInfo structure */
  270.     NULL,   /* user-definable data */
  271.     NULL    /* pointer to user-definable data */
  272. };
  273.  
  274. SHORT infpBorderVectors4[] = {
  275.     0,0,
  276.     55,0,
  277.     55,16,
  278.     0,16,
  279.     0,0
  280. };
  281. struct Border infpBorder4 = {
  282.     -1,-1,  /* XY origin relative to container TopLeft */
  283.     3,0,JAM1,   /* front pen, back pen and drawmode */
  284.     5,  /* number of XY vectors */
  285.     infpBorderVectors4, /* pointer to XY vectors */
  286.     NULL    /* next border in list */
  287. };
  288.  
  289. struct IntuiText infpIText4 = {
  290.     3,0,JAM2,   /* front and back text pens, drawmode and fill byte */
  291.     6,3,    /* XY origin relative to container TopLeft */
  292.     NULL,   /* font pointer or NULL for default */
  293.     "Show", /* pointer to text */
  294.     NULL    /* next IntuiText structure */
  295. };
  296.  
  297. struct Gadget infps1 = {
  298.     &infps2,    /* next gadget */
  299.     167,48, /* origin XY of hit box relative to window TopLeft */
  300.     54,15,  /* hit box width and height */
  301.     NULL,   /* gadget flags */
  302.     RELVERIFY,  /* activation flags */
  303.     BOOLGADGET, /* gadget type flags */
  304.     (APTR)&infpBorder4, /* gadget border or image to be rendered */
  305.     NULL,   /* alternate imagery for selection */
  306.     &infpIText4,    /* first IntuiText structure */
  307.     NULL,   /* gadget mutual-exclude long word */
  308.     NULL,   /* SpecialInfo structure */
  309.     NULL,   /* user-definable data */
  310.     NULL    /* pointer to user-definable data */
  311. };
  312.  
  313. UBYTE infpinfpbord_numSIBuff[4];
  314. struct StringInfo infpinfpbord_numSInfo = {
  315.     infpinfpbord_numSIBuff, /* buffer where text will be edited */
  316.     NULL,   /* optional undo buffer */
  317.     0,  /* character position in buffer */
  318.     4,  /* maximum number of characters to allow */
  319.     0,  /* first displayed character buffer position */
  320.     0,0,0,0,0,  /* Intuition initialized and maintained variables */
  321.     0,  /* Rastport of gadget */
  322.     0,  /* initial value for integer gadgets */
  323.     NULL    /* alternate keymap (fill in if you set the flag) */
  324. };
  325.  
  326. SHORT infpBorderVectors5[] = {
  327.     0,0,
  328.     68,0,
  329.     68,9,
  330.     0,9,
  331.     0,0
  332. };
  333. struct Border infpBorder5 = {
  334.     -1,-1,  /* XY origin relative to container TopLeft */
  335.     3,0,JAM1,   /* front pen, back pen and drawmode */
  336.     5,  /* number of XY vectors */
  337.     infpBorderVectors5, /* pointer to XY vectors */
  338.     NULL    /* next border in list */
  339. };
  340.  
  341. struct Gadget infpbord_num = {
  342.     &infps1,    /* next gadget */
  343.     158,36, /* origin XY of hit box relative to window TopLeft */
  344.     67,8,   /* hit box width and height */
  345.     NULL,   /* gadget flags */
  346.     RELVERIFY,  /* activation flags */
  347.     STRGADGET,  /* gadget type flags */
  348.     (APTR)&infpBorder5, /* gadget border or image to be rendered */
  349.     NULL,   /* alternate imagery for selection */
  350.     NULL,   /* first IntuiText structure */
  351.     NULL,   /* gadget mutual-exclude long word */
  352.     (APTR)&infpinfpbord_numSInfo,   /* SpecialInfo structure */
  353.     NULL,   /* user-definable data */
  354.     NULL    /* pointer to user-definable data */
  355. };
  356.  
  357. SHORT infpBorderVectors6[] = {
  358.     0,0,
  359.     33,0,
  360.     33,12,
  361.     0,12,
  362.     0,0
  363. };
  364. struct Border infpBorder6 = {
  365.     -1,-1,  /* XY origin relative to container TopLeft */
  366.     3,0,JAM1,   /* front pen, back pen and drawmode */
  367.     5,  /* number of XY vectors */
  368.     infpBorderVectors6, /* pointer to XY vectors */
  369.     NULL    /* next border in list */
  370. };
  371.  
  372. struct Gadget infpd2 = {
  373.     &infpbord_num,  /* next gadget */
  374.     128,77, /* origin XY of hit box relative to window TopLeft */
  375.     32,11,  /* hit box width and height */
  376.     NULL,   /* gadget flags */
  377.     RELVERIFY,  /* activation flags */
  378.     BOOLGADGET, /* gadget type flags */
  379.     (APTR)&infpBorder6, /* gadget border or image to be rendered */
  380.     NULL,   /* alternate imagery for selection */
  381.     NULL,   /* first IntuiText structure */
  382.     NULL,   /* gadget mutual-exclude long word */
  383.     NULL,   /* SpecialInfo structure */
  384.     NULL,   /* user-definable data */
  385.     NULL    /* pointer to user-definable data */
  386. };
  387.  
  388. SHORT infpBorderVectors7[] = {
  389.     0,0,
  390.     33,0,
  391.     33,12,
  392.     0,12,
  393.     0,0
  394. };
  395. struct Border infpBorder7 = {
  396.     -1,-1,  /* XY origin relative to container TopLeft */
  397.     3,0,JAM1,   /* front pen, back pen and drawmode */
  398.     5,  /* number of XY vectors */
  399.     infpBorderVectors7, /* pointer to XY vectors */
  400.     NULL    /* next border in list */
  401. };
  402.  
  403. struct Gadget infpu1 = {
  404.     &infpd2,    /* next gadget */
  405.     129,48, /* origin XY of hit box relative to window TopLeft */
  406.     32,11,  /* hit box width and height */
  407.     NULL,   /* gadget flags */
  408.     RELVERIFY,  /* activation flags */
  409.     BOOLGADGET, /* gadget type flags */
  410.     (APTR)&infpBorder7, /* gadget border or image to be rendered */
  411.     NULL,   /* alternate imagery for selection */
  412.     NULL,   /* first IntuiText structure */
  413.     NULL,   /* gadget mutual-exclude long word */
  414.     NULL,   /* SpecialInfo structure */
  415.     NULL,   /* user-definable data */
  416.     NULL    /* pointer to user-definable data */
  417. };
  418.  
  419. SHORT infpBorderVectors8[] = {
  420.     0,0,
  421.     77,0,
  422.     77,16,
  423.     0,16,
  424.     0,0
  425. };
  426. struct Border infpBorder8 = {
  427.     -1,-1,  /* XY origin relative to container TopLeft */
  428.     3,0,JAM1,   /* front pen, back pen and drawmode */
  429.     5,  /* number of XY vectors */
  430.     infpBorderVectors8, /* pointer to XY vectors */
  431.     NULL    /* next border in list */
  432. };
  433.  
  434. struct IntuiText infpIText5 = {
  435.     1,0,JAM2,   /* front and back text pens, drawmode and fill byte */
  436.     20,4,   /* XY origin relative to container TopLeft */
  437.     NULL,   /* font pointer or NULL for default */
  438.     "Quit", /* pointer to text */
  439.     NULL    /* next IntuiText structure */
  440. };
  441.  
  442. struct Gadget infpok1 = {
  443.     &infpu1,    /* next gadget */
  444.     102,108,    /* origin XY of hit box relative to window TopLeft */
  445.     76,15,  /* hit box width and height */
  446.     NULL,   /* gadget flags */
  447.     RELVERIFY,  /* activation flags */
  448.     BOOLGADGET, /* gadget type flags */
  449.     (APTR)&infpBorder8, /* gadget border or image to be rendered */
  450.     NULL,   /* alternate imagery for selection */
  451.     &infpIText5,    /* first IntuiText structure */
  452.     NULL,   /* gadget mutual-exclude long word */
  453.     NULL,   /* SpecialInfo structure */
  454.     NULL,   /* user-definable data */
  455.     NULL    /* pointer to user-definable data */
  456. };
  457.  
  458. #define infpGadgetList1 infpok1
  459.  
  460. struct NewWindow infpNewWindowStructure1 = {
  461.     12,33,  /* window XY origin relative to TopLeft of screen */
  462.     258,128,    /* window width and height */
  463.     0,1,    /* detail and block pens */
  464.     GADGETDOWN+GADGETUP+CLOSEWINDOW,    /* IDCMP flags */
  465.     WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH, /* other window flags */
  466.     &infpok1,   /* first gadget in gadget list */
  467.     NULL,   /* custom CHECKMARK imagery */
  468.     "Info pays",    /* window title */
  469.     NULL,   /* custom screen pointer */
  470.     NULL,   /* custom bitmap */
  471.     5,5,    /* minimum width and height */
  472.     65535,65535,    /* maximum width and height */
  473.     CUSTOMSCREEN    /* destination screen type */
  474. };
  475.  
  476.  
  477. void HandleEvent3(APTR object)
  478. {
  479.   if (object == (APTR)&infpok1) { cmd_ok(); return; }
  480.   if (object == (APTR)&infpu1) { cmd_up(); return; }
  481.   if (object == (APTR)&infpd2) { cmd_down(); return; }
  482.   if (object == (APTR)&infps1) { cmd_show_bord(); return; }
  483.   if (object == (APTR)&infps2) { cmd_del_bord(); return; }
  484.   if (object == (APTR)&infps3) { cmd_add_bord(); return; }
  485.   if (object == (APTR)&infpna) { cmd_newname(); return; }
  486. }
  487. #define HANDLEEVENT HandleEvent
  488.  
  489. /* end of PowerWindows source generation */
  490. /*
  491.  
  492.  
  493. #include "win_info_pays.h"
  494.  
  495. /*************************************************************************/
  496.  
  497. void cmd_add_bord(void)
  498. {
  499.     int i,num_bord,num_add;
  500.     int *p_b;
  501.     COUNTRY *p_c;
  502.  
  503.     num_add = atoi(infpinfpbord_numSIBuff);
  504.     printf ("cmd add bord de %d\n",num_add);
  505.     p_c = &(tab_country[Pref.country_sel]);
  506.     num_bord = (p_c->p_borders)[start_bord];
  507.  
  508.     p_b = p_c->p_borders;
  509.     for (i=p_c->nb_borders;i>=start_bord;i--)
  510.     {
  511.         p_b[i+1]=p_b[i];
  512.     }
  513.     p_b[start_bord] = num_add;
  514.     p_c->nb_borders++;
  515.     aff_borders(Pref.country_sel,start_bord);
  516.     redraw_map(-1,rpG);
  517. }
  518.  
  519. /*************************************************************************/
  520.  
  521. void    inf_loop(void)
  522. {
  523.     UWORD code;
  524.     ULONG class;
  525.     APTR object;
  526.     struct IntuiMessage *message;
  527.     int x,y;
  528.  
  529.     flg_quit_inf=FALSE;
  530.     do
  531.     {
  532.         WaitPort(inf_wG->UserPort);
  533.         while( (message = (struct IntuiMessage *)
  534.                 GetMsg(inf_wG->UserPort) ) != NULL)
  535.         {
  536.             code = message->Code;  /* MENUNUM */
  537.             class = message->Class;
  538.             object = message->IAddress;  /* Gadget */
  539.             x= message->MouseX;
  540.             y= message->MouseY;
  541.             ReplyMsg((struct Message *)message);
  542.             if ( class == CLOSEWINDOW ) (flg_quit_inf = TRUE);
  543.             if (( class == GADGETUP ) ||    /* Gagdets */
  544.                 ( class == GADGETDOWN ))
  545.             {
  546.  
  547.                 HandleEvent3(object);
  548.             }
  549.         }
  550.     }
  551.       while(flg_quit_inf==FALSE);
  552. }
  553.  
  554.  
  555. /*************************************************************************/
  556. void    aff_borders(
  557.     int num,
  558.     int start
  559.     )
  560.     
  561. {
  562.     int i,*p_bord;
  563.     char    buf[100];
  564.     i=0;
  565.  
  566.     p_bord=tab_country[num].p_borders;
  567.     while ((i<5)&&(i+start)<tab_country[num].nb_borders)
  568.     {
  569.         sprintf(buf,"%04d  ",p_bord[i+start]);
  570.         IPrint(inf_rpG,10,55+10*i,buf,-1);
  571.         i++;
  572.     }
  573.     if (i<5)
  574.     {
  575.         IPrint(inf_rpG,10,55+10*i,"    ",-1);
  576.     }
  577. }
  578.  
  579. /*************************************************************************/
  580. void init_window(int num)
  581. {
  582.     aff_borders(num,0);
  583.     start_bord=0;
  584. }
  585. /*************************************************************************/
  586.  
  587. void cmd_edit_pays(void)
  588. {
  589.     printf ("cmd edit pays!\n");
  590.     infpNewWindowStructure1.Screen = sC;
  591.     strcpy (infpinfpnaSIBuff,tab_country[Pref.country_sel].name);
  592.     inf_wG = OpenWindow(&infpNewWindowStructure1);
  593.     if (inf_wG==NULL)
  594.     {
  595.         printf("Erreur ouverture window!\n");
  596.     }
  597.     else
  598.     {
  599.         inf_rpG=inf_wG->RPort;
  600.         init_window(Pref.country_sel);
  601.         inf_loop();
  602.         CloseWindow(inf_wG);
  603.     }
  604. }
  605.  
  606. void cmd_ok(void)
  607. {
  608.     printf("cmd ok!\n");
  609.     flg_quit_inf=TRUE;
  610. }
  611.  
  612.  
  613.  
  614. /*************************************************************************/
  615.  
  616. void    edit_loop(  struct IntuiMessage *message)
  617. {
  618.     UWORD code;
  619.     ULONG class;
  620.     APTR object;
  621.     static  int flg_press=FALSE;
  622.     static  VECT    *v,*tv;
  623.     static  int num_pt,num_bord,num_pt_avant,num_pt_apres;
  624.     static  int flg_found;
  625.     static  ULONG   seconds,micros;
  626.     static  ULONG   n_seconds,n_micros,ds,dm;
  627.     static  int old_seg =-1;
  628.     static  int x,y,old_x,old_y,x2,y2;
  629.  
  630.     code = message->Code;  /* MENUNUM */
  631.     class = message->Class;
  632.     object = message->IAddress;  /* Gadget */
  633.     x= message->MouseX;
  634.     y= message->MouseY;
  635.     seconds=message->Seconds;
  636.     micros =message->Micros;
  637.  
  638.     switch (class)
  639.     {
  640.         case VANILLAKEY:
  641.         if ((commande==ADD_SEGMENT) && (code==' '))
  642.         {
  643.             char    Buffer[10];
  644.             int i,num;
  645.             int mx,my,MX,MY;
  646.             char    c;
  647.  
  648.             printf("Fin pays!\n Ce pays contient les vecteurs:\n");
  649.  
  650.             for (i=0;i<num_vect;i++)
  651.             {
  652.                 printf("[%2d]:%04d\n",i,tab_vecteur_temp[i]);
  653.             }
  654.             printf ("Correct?(o/n)\n");
  655.             do
  656.             {
  657.                 c =getchar();
  658.                 printf("c=%c\n",c);
  659.             }
  660.              while ((c!='o') && (c!='n'));
  661.             if (c=='o')
  662.             {
  663.                 printf("Ok....\nQuel est le nom du pays?");
  664.                 scanf("%s",Buffer);
  665.                 printf("Va pour %s\n",Buffer);
  666.  
  667.                 mx=100000;
  668.                 my=100000;
  669.                 MX=-100000;
  670.                 MY=-100000;
  671.  
  672.                 tab_country[max_country].name=(char *)malloc(strlen(Buffer)+1);
  673.                 strcpy(tab_country[max_country].name,Buffer);
  674.  
  675.                 tab_country[max_country].p_borders=(int *)malloc((10+num_vect)*sizeof(int));
  676.                 for (i=0;i<num_vect;i++)
  677.                 {
  678.                     num=tab_vecteur_temp[i];
  679.                     tab_country[max_country].p_borders[i]=num;
  680.                     tstpt(  tab_vect[i].b_clip.minx,
  681.                         tab_vect[i].b_clip.maxy,
  682.                         &mx,&my,&MX,&MY);
  683.                     tstpt(  tab_vect[i].b_clip.maxx,
  684.                         tab_vect[i].b_clip.maxy,
  685.                         &mx,&my,&MX,&MY);
  686.                 }
  687.  
  688.                 tab_country[max_country].nb_borders=num_vect;
  689.                 tab_country[max_country].pnb1=0;
  690.                 tab_country[max_country].pnb2=0;
  691.                 tab_country[max_country].pnb3=0;
  692.                 tab_vect[num_bord].b_clip.minx=mx;
  693.                 tab_vect[num_bord].b_clip.miny=my;
  694.                 tab_vect[num_bord].b_clip.maxx=MX;
  695.                 tab_vect[num_bord].b_clip.maxy=MY;
  696.                 /* un pays est ajouté */
  697.                 max_country++;
  698.             }
  699.             num_vect=0;
  700.         }
  701.         if ( code =='s')
  702.         {
  703.             save_zones("Out_Temp");
  704.         }
  705.         if ( code =='r')
  706.         {
  707.             redraw_map_complete(rpG);
  708.         }
  709.         if ((code>='1')&&(code<='5'))
  710.         {
  711.             map_set_prof(code-'0');
  712.             redraw_map_complete(rpG);
  713.         }
  714.         break;
  715.         case MOUSEBUTTONS:
  716.         if (code==SELECTDOWN)
  717.         {
  718.           printf("Sel\n");
  719.           switch(commande)
  720.           {
  721.  
  722.             case MOVE_PT:
  723.             flg_press=TRUE;
  724.             flg_found=map_find_pt(rpG,x,y,&v,&num_pt,&num_bord);
  725.             if(flg_found==TRUE)
  726.             {
  727.                 tv=tab_vect[num_bord].p_vect;
  728.                 if (num_pt==0)
  729.                 {
  730.                     num_pt_avant=num_pt;
  731.                     num_pt_apres=1;
  732.                 }
  733.                 else 
  734.                 if(num_pt==tab_vect[num_bord].nb_vect-1)
  735.                 {
  736.                     num_pt_avant=num_pt-1;
  737.                     num_pt_apres=num_pt;
  738.                 }
  739.                 else
  740.                 {
  741.                     num_pt_avant=num_pt-1;
  742.                     num_pt_apres=num_pt+1;
  743.                 }
  744.                 SetDrMd(rpG,COMPLEMENT);
  745. /*
  746.                 DrawSeg(rpG,tv,num_pt_avant,num_pt,num_pt_apres);
  747. */
  748.             }
  749.             break;
  750.             case ADD_SEGMENT:
  751.             printf("Add segment:%d\n",old_seg);
  752.             tab_vecteur_temp[num_vect]=old_seg;
  753.             num_vect++;
  754.             {
  755.                 char    Buffer[10];
  756.                 int i;
  757.  
  758.                 for(i=0;i<num_vect;i++)
  759.                 {
  760.                     sprintf(Buffer,"%04d",tab_vecteur_temp[i]);
  761.                     IPrint(rpG,30,40+8*i,Buffer,-1);
  762.                 }
  763.             }
  764.  
  765.             break;
  766.             default:
  767.             break;
  768.            }
  769.         }
  770.         if (code==SELECTUP)
  771.         {
  772.             printf("Sel up\n");
  773.             flg_press=FALSE;
  774.            switch (commande)
  775.            {
  776.               case MOVE_PT:
  777.             if(flg_found==TRUE)
  778.             {
  779.                 flg_found=FALSE;
  780.                 redraw_map(-1,rpG);
  781.             }
  782.             break;
  783.              case ADD_SEGMENT:
  784.             old_seg=-1;
  785.             break;
  786.             }
  787.         }
  788.         break;
  789.         case MOUSEMOVE:
  790.         CurrentTime (&n_seconds,&n_micros);
  791.         ds=n_seconds-seconds;
  792.         dm=n_micros -micros;
  793.         if ((ds==0)&&(dm<50000))
  794.         {
  795.            switch (commande)
  796.            {
  797.             case MOVE_PT:
  798.                 if ((flg_press==TRUE)&&(flg_found==TRUE))
  799.                 {
  800.                     SetDrMd(rpG,COMPLEMENT);
  801.                     DrawSeg(rpG,tv,num_pt_avant,num_pt,num_pt_apres);
  802.                     x2=x;
  803.                     y2=y;
  804.                     conv_inv_xy(&x2,&y2);
  805.                     v->x=x;
  806.                     v->y=y;
  807.                     DrawSeg(rpG,tv,num_pt_avant,num_pt,num_pt_apres);
  808.                 }
  809.                 break;
  810.              case ADD_SEGMENT:
  811.             {
  812.                 int num_seg;
  813.  
  814.                 num_seg=map_find_segment(x,y);
  815.                 if(num_seg!=old_seg){
  816.                     if(old_seg!=-1){
  817.                         map_draw_segment(rpG,old_seg,2);
  818.                     }
  819.                     if(num_seg!=-1){
  820.                         char    buffer[10];
  821.                         map_draw_segment(rpG,num_seg,9);
  822.                         sprintf(buffer,"%04d",num_seg);
  823.                         IPrint(rpG,20,20,buffer,-1);
  824.                     }
  825.                     old_seg=num_seg;
  826.                 }
  827.             }
  828.             break;
  829.             default:
  830.             break;
  831.            }
  832.            old_x=x;
  833.            old_y=y;
  834.         }
  835.         break;
  836.         }
  837.  
  838. }
  839.  
  840.